//
//  MainTab.m
//  lvjin
//
//  Created by  on 12-5-17.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MainTab.h"
#import "UIView+Frame.h"


#define kNormalColor        [UIColor whiteColor]
#define kSelectedtedColor   [UIColor colorWithRed:255 green:215 blue:0 alpha:1]

@interface MainTab()
{
    IBOutlet UIButton * firstButton;
    IBOutlet UIButton * secondButton;
    IBOutlet UIButton * thirdButton;
    IBOutlet UIButton * fourthButton;
}

@property (retain, nonatomic) IBOutlet UILabel *firstLbl;
@property (retain, nonatomic) IBOutlet UILabel *secondLbl;
@property (retain, nonatomic) IBOutlet UILabel *thirdLbl;
@property (retain, nonatomic) IBOutlet UILabel *forthLbl;

@property (retain, nonatomic) IBOutlet UIImageView *centerBg;

@end

@implementation MainTab
@synthesize firstLbl;
@synthesize secondLbl;
@synthesize thirdLbl;
@synthesize forthLbl;
//@synthesize fifthLbl;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

+ (MainTab *)getInstance
{
    MainTab * instance = [[[NSBundle mainBundle] loadNibNamed:@"MainTab" owner:nil options:nil] lastObject];
    [instance initTabBarStatus];
    return instance;
}

- (void)configClickWithTarget:(id)target selector:(SEL)selector;
{
    [firstButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    [secondButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    [thirdButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
    [fourthButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
//    [fifthButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
}

- (void)initTabBarStatus
{
    firstButton.tag  = 0;
    secondButton.tag = 1;
    thirdButton.tag  = 2;
    fourthButton.tag = 3;
//    fifthButton.tag  = 4;
    
    [self.centerBg setFrame:CGRectMake(_centerBg.left, -2.72, _centerBg.width, _centerBg.height)];
    
    [self effectWithTag:0];
}

- (void)setImage:(UIImage *)image forBtn:(UIButton *)btn
{
    [btn setBackgroundImage:image forState:UIControlStateNormal];
}

- (void)effectWithTag:(NSInteger)tag
{
    if (tag == 0)
    {
        [self setImage:[UIImage imageNamed:@"taxi1.png"] forBtn:firstButton];
//        [firstButton setTitleColor:kYellow forState:UIControlStateNormal];
        [firstLbl setTextColor:kSelectedtedColor];
        
        [self setImage:[UIImage imageNamed:@"appoint0.png"] forBtn:secondButton];
//        [secondButton setTitleColor:kRed forState:UIControlStateNormal];
        [secondLbl setTextColor:kNormalColor];
        
        [self setImage:[UIImage imageNamed:@"order0.png"] forBtn:thirdButton];
//        [thirdButton setTitleColor:kRed forState:UIControlStateNormal];
        [thirdLbl setTextColor:kNormalColor];
        
        [self setImage:[UIImage imageNamed:@"more0.png"] forBtn:fourthButton];
//        [fourthButton setTitleColor:kRed forState:UIControlStateNormal];
        [forthLbl setTextColor:kNormalColor];
        
//        [self setImage:[UIImage imageNamed:@"setting.png"] forBtn:fifthButton];
////        [fifthButton setTitleColor:kRed forState:UIControlStateNormal];
//        [fifthLbl setTextColor:kNormalColor];
    }
    else if (tag == 1)
    {
        [self setImage:[UIImage imageNamed:@"taxi0.png"] forBtn:firstButton];
//        [firstButton setTitleColor:kRed forState:UIControlStateNormal];
        [firstLbl setTextColor:kNormalColor];

        [self setImage:[UIImage imageNamed:@"appoint1.png"] forBtn:secondButton];
//        [secondButton setTitleColor:kYellow forState:UIControlStateNormal];
        [secondLbl setTextColor:kSelectedtedColor];

        [self setImage:[UIImage imageNamed:@"order0.png"] forBtn:thirdButton];
//        [thirdButton setTitleColor:kRed forState:UIControlStateNormal];
        [thirdLbl setTextColor:kNormalColor];

        [self setImage:[UIImage imageNamed:@"more0.png"] forBtn:fourthButton];
//        [fourthButton setTitleColor:kRed forState:UIControlStateNormal];
        [forthLbl setTextColor:kNormalColor];
        
//        [self setImage:[UIImage imageNamed:@"setting.png"] forBtn:fifthButton];
////        [fifthButton setTitleColor:kRed forState:UIControlStateNormal];
//        [fifthLbl setTextColor:kNormalColor];
    }
    else if (tag == 2)
    {
        [self setImage:[UIImage imageNamed:@"taxi0.png"] forBtn:firstButton];
//        [firstButton setTitleColor:kRed forState:UIControlStateNormal];
        [firstLbl setTextColor:kNormalColor];

        [self setImage:[UIImage imageNamed:@"appoint0.png"] forBtn:secondButton];
//        [secondButton setTitleColor:kRed forState:UIControlStateNormal];
        [secondLbl setTextColor:kNormalColor];

        [self setImage:[UIImage imageNamed:@"order1.png"] forBtn:thirdButton];
//        [thirdButton setTitleColor:kYellow forState:UIControlStateNormal];
        [thirdLbl setTextColor:kSelectedtedColor];

        [self setImage:[UIImage imageNamed:@"more0.png"] forBtn:fourthButton];
//        [fourthButton setTitleColor:kRed forState:UIControlStateNormal];
        [forthLbl setTextColor:kNormalColor];
        
//        [self setImage:[UIImage imageNamed:@"setting.png"] forBtn:fifthButton];
////        [fifthButton setTitleColor:kRed forState:UIControlStateNormal];
//        [fifthLbl setTextColor:kNormalColor];
    }
    else if (tag == 3)
    {
        [self setImage:[UIImage imageNamed:@"taxi0.png"] forBtn:firstButton];
//        [firstButton setTitleColor:kRed forState:UIControlStateNormal];
        [firstLbl setTextColor:kNormalColor];

        [self setImage:[UIImage imageNamed:@"appoint0.png"] forBtn:secondButton];
//        [secondButton setTitleColor:kRed forState:UIControlStateNormal];
        [secondLbl setTextColor:kNormalColor];

        [self setImage:[UIImage imageNamed:@"order0.png"] forBtn:thirdButton];
//        [thirdButton setTitleColor:kRed forState:UIControlStateNormal];
        [thirdLbl setTextColor:kNormalColor];

        [self setImage:[UIImage imageNamed:@"more1.png"] forBtn:fourthButton];
//        [fourthButton setTitleColor:kYellow forState:UIControlStateNormal];
        [forthLbl setTextColor:kSelectedtedColor];
        
//        [self setImage:[UIImage imageNamed:@"setting.png"] forBtn:fifthButton];
////        [fifthButton setTitleColor:kRed forState:UIControlStateNormal];
//        [fifthLbl setTextColor:kNormalColor];
    }
    else if (tag == 4)
    {
        [self setImage:[UIImage imageNamed:@"home.png"] forBtn:firstButton];
//        [firstButton setTitleColor:kRed forState:UIControlStateNormal];
        [firstLbl setTextColor:kNormalColor];
        
        [self setImage:[UIImage imageNamed:@"myLine.png"] forBtn:secondButton];
//        [secondButton setTitleColor:kRed forState:UIControlStateNormal];
        [secondLbl setTextColor:kNormalColor];
        
        [self setImage:[UIImage imageNamed:@"shoppingCart0.png"] forBtn:thirdButton];
//        [thirdButton setTitleColor:kRed forState:UIControlStateNormal];
        [thirdLbl setTextColor:kNormalColor];
        
        [self setImage:[UIImage imageNamed:@"search.png"] forBtn:fourthButton];
//        [fourthButton setTitleColor:kRed forState:UIControlStateNormal];
        [forthLbl setTextColor:kNormalColor];
        
//        [self setImage:[UIImage imageNamed:@"setting.png"] forBtn:fifthButton];
////        [fifthButton setTitleColor:kYellow forState:UIControlStateNormal];
//        [fifthLbl setTextColor:kSelectedtedColor];
    }
}

@end
